package JDBC;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo6 {
    public static void main(String[] args) throws SQLException {
        Connection conn = DBUtil.getConnection();
        Statement state = conn.createStatement();
        String sql = "SELECT s.name,s.age,c.name,t.name "+
                     "FROM teacher t "+
                     "JOIN class c ON c.teacher_id=t.id "+
                     "JOIN student s ON c.id = s.class_id "+
                     "WHERE t.name='刘苍松';";
        ResultSet rs = state.executeQuery(sql);
        while (rs.next()){
            String name = rs.getString("s.name");
            int age = rs.getInt("s.age");
            String c_name=rs.getString("c.name");
            String t_name=rs.getString("t.name");
            System.out.println(name+","+age+","+c_name+","+t_name);
        }
        conn.close();
    }

}
